<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>排除词配置</title>
    <link rel="stylesheet" href="../../../assert/css/font.css" th:href="@{/assert/css/font.css}"/>
    <link rel="stylesheet" href="../../../assert/css/plugin/chosen/chosen.css"
          th:href="@{/assert/css/plugin/chosen/chosen.css}"/>
    <link href="../../../assert/css/animate.min.css" rel="stylesheet" th:href="@{/assert/css/animate.min.css}">
    <link href="../../../assert/css/plugin/toastr/toastr.min.css" rel="stylesheet"
          th:href="@{/assert/css/plugin/toastr/toastr.min.css}">
    <link href="../../../assert/css/plugin/jsTree/themes/default/style.css" rel="stylesheet"
          th:href="@{/assert/css/plugin/jsTree/themes/default/style.css}">
    <link href="../../../assert/js/layui/css/layui.css" rel="stylesheet"
          th:href="@{/assert/js/layui/css/layui.css}" media="all">
    <link href="../../../assert/css/loaders.css" rel="stylesheet"
          th:href="@{/assert/css/loaders.css}">
    <link rel="stylesheet" href="../../../assert/css/bootstrap.min.css" th:href="@{/assert/css/bootstrap.min.css}"/>
    <link href="../../../assert/css/plugin/bootstrap-table/bootstrap-table.min.css" rel="stylesheet"
          th:href="@{/assert/css/plugin/bootstrap-table/bootstrap-table.min.css}">
    <link rel="stylesheet" href="../../../assert/css/jquery-ui.css" th:href="@{/assert/css/jquery-ui.css}"/>
    <link rel="stylesheet" href="../../../assert/js/bootstrap-fileinput/css/fileinput.min.css"
          th:href="@{/assert/js/bootstrap-fileinput/css/fileinput.min.css}"/>
    <link href="../../../assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/styles/jqx.base.css" rel="stylesheet"
          th:href="@{/assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/styles/jqx.base.css}"/>
    <link rel="stylesheet" href="../../../assert/css/index.css" th:href="@{/assert/css/index.css(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"/>
    <style>
        .table_msg {
            width: 100%;
            border: 1px solid #e4eaec;
            padding: 0px 10px;
            position: relative;
            top: 6px;
            background: #ddd;
        }

        .layui-form-switch {
            width: 48px;
        }

        .search_group label.control-label {
            width: 85px;
        }
        .remarkBox .jqx-validator-error-label{
            top: 115px !important;
        }
        .form-group{
            display: inline-block;
            width: 100%;
        }
        #importModal .form-group label{
            text-align: right;
            margin-top: 6px;
        }
    </style>
</head>
<body class="oneStyle">
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="tools_bar">
            <div class="pull-left">
                <a href="#" class="btn btn-default active" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 隐藏</a>
                <a href="#" class="btn btn-default active" id="refresh"><i class="fa fa-refresh"></i> 刷新</a>
                <a href="#" class="btn btn-default active" id="btnAdd" title="添加排除词"><i class="fa fa-plus"></i> 添加</a>
                <a href="#" class="btn btn-default active" id="btnEdit" title="编辑排除词"><i class="fa fa-pencil"></i>
                    编辑</a>
                <a href="#" class="btn btn-default active" id="btnDel" title="删除排除词"><i class="fa fa-remove"></i>
                    删除</a>
                <!--<a href="#" class="btn btn-default active" id="btnAllAdd" title="导入排除词"><i class="fa fa-plus"></i> 导入</a>-->
                <a href="#" style="margin-left:20px" class="btn btn-default active" id="btnStart" title="启用排除词"><i
                        class="fa fa-long-arrow-up stateGreen"></i> 启用</a>
                <a href="#" class="btn btn-default active" id="btnStop" title="停用排除词"><i
                        class="fa fa-long-arrow-down stateRed"></i> 停用</a>
            </div>
        </div>
        <div class="search on">
            <div class="search_group">
                <label class="control-label">省份：</label>
                <div class="control-inline">
                    <select type="text" id="pro" value="" class="form-control search_input"></select>
                </div>
            </div>
            <div class="search_group">
                <label class="control-label">排除词名称：</label>
                <div class="control-inline">
                    <input type="text" id="keyName" value="" class="form-control search_input" autocomplete="off">
                </div>
            </div>
            <div class="search_group">
                <label class="control-label">状态：</label>
                <div class="control-inline">
                    <select type="text" id="state" value=""
                            class="form-control search_input chosen-select"></select>
                </div>
            </div>
            <div class="search_group">
                <label class="control-label">创建时间：</label>
                <div class="control-inline">
                    <input placeholder="开始日期" class="form-control layer-date search_input" id="start"
                           autocomplete="off"> -
                    <input placeholder="结束日期" class="form-control layer-date search_input" id="end"
                           autocomplete="off">
                </div>
            </div>
            <div class="search_group">
                <button id="search" class="btn  btn-primary">查询</button>
                <button id="reset" class="btn  btn-default">重置</button>
                <button id="export" class="btn  btn-default">导出</button>
            </div>
        </div>
        <table id="myTable"></table>
    </div>
</div>
<!--添加关键词-->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog" style="width:900px !important;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span
                        aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title">添加排除词</h4>
            </div>
            <div class="modal-body">
                <form method="post" class="form-horizontal" id="addModelForm">
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label" style="width:21%;"><span class="respan">*</span>省份:</label>
                        <div class="col-sm-8" style="width: 70.6%;">
                            <select name="" id="proAdd"></select>
                            <input type="text" class="form-control selectInput" id="proModalAddInput" autocomplete="off">
                        </div>
                    </div>
                    <div class="form-group remarkBox">
                        <label for="" class="col-sm-3 control-label" style="width:21%;"><span class="respan">*</span>排除词:</label>
                        <div class="col-sm-8" style="width: 70.6%;">
                            <span style="color: #ef9407;">支持汉字、英文、数字组合，可同时添加多个排除词，请用英文输入法“,”（逗号）隔开，关键词内不能包含符号与空格，最后一个词尾不用加标点符号。
例：欢迎,您好,A卡套餐</span>
                            <textarea name="note" class="form-control" style="height:70px;" id="keyAdd"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="save">保存</button>
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
            </div>

        </div>
    </div>
</div>
<!--编辑排除词-->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog" style="width:900px !important;">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span
                        aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title">编辑排除词</h4>
            </div>
            <div class="modal-body">
                <form method="post" class="form-horizontal" id="editModelForm">
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label" style="width:21%;"><span class="respan">*</span>省份:</label>
                        <div class="col-sm-8" style="width: 70.6%;">
                            <select id="proEdit" disabled></select>
                            <input type="text" class="form-control selectInput" id="proModalEditInput" autocomplete="off" name="province_code">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label" style="width:21%;"><span class="respan">*</span>排除词:</label>
                        <div class="col-sm-8" style="width: 70.6%;">
                            <input name="note" class="form-control" id="keyEdit"/>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="saveEdit">保存</button>
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
            </div>

        </div>
    </div>
</div>
<!--删除确认框-->
<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                    <h4 class="modal-title">删除</h4>
                </div>
                <div class="modal-body">
                    <div style="text-align: center">
                        <span class="fa fa-question-circle"></span>
                        <span id="delName"></span>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="delBtn">确定</button>
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!--上线/下线确认框-->
<div class="modal fade" id="startModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                    <h4 class="modal-title">上线</h4>
                </div>
                <div class="modal-body">
                    <div style="text-align: center">
                        <div>
                            <div class="tipBox"></div>
                        </div>
                        <span class="fa fa-question-circle"></span>
                        <span id="type"></span>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="startBtn">确定</button>
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!--导入排除词-->
<div class="modal fade" id="importModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                    <h4 class="modal-title">导入</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label"><span class="respan">*</span>省份：</label>
                        <div class="col-sm-8">
                            <select name="province_code" id="proModal" data-code="pro"></select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label"><span class="respan">*</span>上传：</label>
                        <div class="col-sm-8" id="uploadDiv">

                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label"></label>
                        <div class="col-sm-8">
                            <button type="button" class="btn btn-outline btn-default"
                                    onclick="window.location.href=basePath+'app/template/重点关键词导入模板.xlsx';">
                                点击获取模板文件
                            </button>
                            <div>
                                <!--<ul class="importTips">-->
                                <!--<li><span>●</span>不选省份则默认导入到集团中。</li>-->
                                <!--</ul>-->
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="importBtn">确定</button>
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>
<form action="" id="exportForm" class="hidden" method="post" target="_self">
    <input type="text" name="province">
    <input type="text" name="word_name">
    <input type="text" name="word_status">
    <input type="text" name="create_time_start">
    <input type="text" name="create_time_end">
</form>
<a id="basePath" th:href="@{/}"></a>
<script src="../../../assert/js/jquery.js" th:src="@{/assert/js/jquery.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/bootstrap.min.js" th:src="@{/assert/js/bootstrap.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/plugin/bootstrap-table/bootstrap-table.min.js"
        th:src="@{/assert/js/plugin/bootstrap-table/bootstrap-table.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/plugin/bootstrap-table/bootstrap-table-mobile.min.js"
        th:src="@{/assert/js/plugin/bootstrap-table/bootstrap-table-mobile.min.js}"></script>
<script src="../../../assert/js/plugin/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"
        th:src="@{/assert/js/plugin/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
<script src="../../../assert/js/plugin/toastr/toastr.min.js"
        th:src="@{/assert/js/plugin/toastr/toastr.min.js}"></script>
<script src="../../../assert/js/base.js" th:src="@{/assert/js/base.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/jquery-ui.min.js" th:src="@{/assert/js/jquery-ui.min.js}"></script>
<script src="../../../assert/js/plugin/layer/laydate/laydate.js"
        th:src="@{/assert/js/plugin/layer/laydate/laydate.js}"></script>
<script src="../../../assert/js/changeTime.js" th:src="@{/assert/js/changeTime.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/plugin/jsTree/jstree.min.js"
        th:src="@{/assert/js/plugin/jsTree/jstree.min.js}"></script>
<script src="../../../assert/js/plugin/chosen/chosen.jquery.js"
        th:src="@{/assert/js/plugin/chosen/chosen.jquery.js}"></script>
<script src="../../../assert/js/layui/layui.js" th:src="@{/assert/js/layui/layui.js}"></script>
<script src="../../../assert/js/common.js" th:src="@{/assert/js/common.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxcore.js"
        th:src="@{/assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxcore.js}"></script>
<script src="../../../assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxvalidator.js"
        th:src="@{/assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxvalidator.js}"></script>
<script src="../../../assert/js/bootstrap-fileinput/js/fileinput.min.js"
        th:src="@{/assert/js/bootstrap-fileinput/js/fileinput.min.js}"></script>
<script src="../../../assert/js/bootstrap-fileinput/js/locales/zh.js"
        th:src="@{/assert/js/bootstrap-fileinput/js/locales/zh.js}"></script>
<script>
    //项目名称
    var basePath = $("#basePath").attr("href");
    var json = [];
    var TableInit = function () {
        var oTableInit = new Object();
        var url =tools.url+'/excludeword/queryWord';
        var height = ($(window).height() -$(".tools_bar").height()-9-$(".search").height()-40);
        //初始化Table
        oTableInit.Init = function () {
            $('#myTable').bootstrapTable("destroy");
            $('#myTable').bootstrapTable({
                url: url,         //请求后台的URL（*）
                method: 'post',                      //请求方式（*）
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                height:height,
                sortable: false,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                responseHandler: function (res) {
                    tools.tableData = res.data.rows;
                    return {
                        "total": res.data.total,//总页数
                        "rows": res.data.rows   //数据
                    };
                },
                pagination: true, // 是否显示分页（*）
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                contentType: "application/x-www-form-urlencoded",
                strictSearch: true,
                showColumns: false,                  //是否显示所有的列
                showRefresh: false,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                uniqueId: "no",                     //每一行的唯一标识，一般为主键列
                showToggle: false,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,
                cellStyle: {
                    css: {"background-color": "#fff"}
                },//是否显示父子表
                queryParams: function (params) {
                    var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        pageSize: params.limit,   //页面大小
                        pageNum: params.offset/params.limit+1,  //偏移量
                        province_code:  $("#pro").val(),
                        word_name: $.trim($("#keyName").val()),//名称
                        word_status: $("#state").val(),//状态
                        create_time_start: $("#start").val(),//开始日期
                        create_time_end: $("#end").val() //结束日期
                    };
                    return temp;
                },
                columns: [
                    {
                        checkbox: true, // 显示一个勾选框
                        align: 'center' // 居中显示
                    },
                    {
                        align: "center",
                        halign: "center",
                        title: '序号',//标题  可不加
                        width: 60,
                        field: 'number',
                        formatter: function (value, row, index) {
                            var getOptions = $("#myTable").bootstrapTable('getOptions');
                            var pagenum = getOptions.pageNumber;
                            var pagesize = getOptions.pageSize;
                            var st = (pagenum - 1) * pagesize;
                            return (st + index + 1) + "";
                        }
                    },
                    {
                        align: "center",
                        halign: "center",
                        field: 'province',
                        title: '省份'
                    },
                    {
                        align: "center",
                        halign: "center",
                        field: 'word_name',
                        title: '排除词'
                    }, {
                        align: "center",
                        halign: "center",
                        field: 'word_status',
                        title: '状态',
                        formatter: function (value, row, index) {
                            var str = "";
                            var color = "#000";
                            if (value == "1") {
                                color = "stateGreen";
                            }
                            str = bs.changeState(value, tools.stateArr);
                            return "<span class='" + color + "'>" + str + "</span>";
                        }
                    }, {
                        align: "center",
                        halign: "center",
                        field: 'create_time',
                        title: '创建时间'
                    }
                ],
                onLoadSuccess: function (data) {  //加载成功时执行
                    resize.me();
                    if (!data.total || data.total == 0) {
                        var src = basePath + "/assert/image/nodata.png";
                        $(".no-records-found").find("td").html('<img src="' + src + '" th:src="@{/assert/image/nodata.png}" style="width:165px;" alt="">');
                    }
                },
                onLoadError: function () {  //加载失败时执行
                    var src = basePath + "/assert/image/nodata.png";
                    $(".no-records-found").find("td").html('<img src="' + src + '" th:src="@{/assert/image/nodata.png}" style="width:165px;" alt="">');
                },
                formatLoadingMessage: function () {
                    return '<div class="loaded">' +
                        '<div class="loader">' +
                        '<div class="loader-inner line-scale-pulse-out">' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '</div>' +
                        '</div>' +
                        '</div>' +
                        '<div>请稍等，数据正在加载中...</div>';
                }
            });
        };
        return oTableInit;
    };
    var resize = {
        init: function () {
            resize.me();
            $(window).resize(function () {
                resize.me();
            })
        },
        me: function () {
            var winW = $(window).width();
            var winH = $(window).height();
            $(".ibox").width(winW - 20);
            $(".ibox").height(winH - 25);
            $("#jstree").height(winH - 60);
            $(".model_right").width(winW - 240);
            bs.autoTableHeight($('#myTable'),winH -$(".tools_bar").height()-22-$(".search").height())
         }
    };
    var tools = {
        maxTextLength:null,
        ruleUrl: "",
        tableData: [],
        ruleTableData: [],
        classifyArr: [],
        stateArr: [
            {
                name: "全部",
                value: ""
            }
        ],
        seatIdArr: [],
        seatAllArr: [],
        proArr: [],//存放省份信息
        url:null,
        init: function () {
            tools.getConfig();
            tools.selectProvince();
            tools.selectInit();
            tools.tabSearch();
            tools.enterSearch();
            tools.search();
            tools.reset();
            tools.refresh();
            tools.addModel();
            tools.editModel();
            tools.saveModel();
            tools.delModel();
            tools.startModel();
            tools.stopModel();
            tools.export();
            importfile.init();
            $("#addModal").on("hidden.bs.modal", function () {
                var form = $("#addModelForm");
                tools.hideLabel(form, '#keyAdd');
                tools.hideLabel(form,'#proModalAddInput');
                $("#keyAdd").removeClass("jqx-validator-error-element");
                $(".jqx-validator-hint").remove();
            });
            $("#editModal").on("hidden.bs.modal", function () {
                var form = $("#editModelForm");
                tools.hideLabel(form, '#keyEdit');
            });
            $(".form-horizontal").on("click", "#radio_box input", function () {
                $(this).prop("checked", true);
                $(this).siblings("input").prop("checked", false);
            })

        },
        selectProvince: function () {//省份下拉框初始化
            tools.proArr = bs.getProvince();
            bs.selectDown($("#pro"), tools.proArr, "");
            bs.selectDown($("#proAdd"), tools.proArr, "","100%");
            bs.selectDown($("#proEdit"), tools.proArr, "","100%");
        },
        hideLabel: function (form, input) {
            form.jqxValidator('hideHint', input);
        },
        getConfig: function () {
            var maxNum= bs.getSysConfig("NAME_LIMIT");
            var num=50;
            if(maxNum){
                num=maxNum.value
            }
            tools.maxTextLength= num;
            tools.url=bs.getSysConfig("ZDYW_KEY").value;
        },
        selectInit: function () {
            bs.dataTime("#start", "#end");
            tools.getState();
            tools.getTestState();
            tools.selectChange($("#proAdd"),$("#proModalAddInput"));
            $("#proEdit").attr("disabled",true).trigger("chosen:updated");
        },
        selectChange: function ($elem, $input) {
            $elem.on("change", function (event, sel) {
                $input.val(sel.selected);
                if (sel.selected == "") {
                    $input.next().html("").css("display", "none !important");
                }
            });
        },
        getState: function () {
            tools.stateArr = bs.getDownData("key_status");
            bs.selectDown($("#state"), tools.stateArr);
        },
        getTestState: function () {
            tools.testStateArr = bs.getDownData("model_is_test");
        },
        changeState: function (value) {
            var str = "";
            for (var i = 0; i < tools.stateArr.length; i++) {
                if (value == tools.stateArr[i].value) {
                    str = tools.stateArr[i].name
                }
            }
            return str;
        },
        tabSearch: function () {
            var search = $(".search");
            $("#btnSearch").on("click", function () {
                if (search.hasClass("on")) {
                    search.slideUp();
                    search.removeClass("on");
                    $("#btnSearch").html('<i class="fa fa-filter"></i> 查询').attr("title", "显示查询条");
                } else {
                    search.slideDown();
                    search.addClass("on");
                    $("#btnSearch").html('<i class="fa fa-filter"></i> 隐藏').attr("title", "隐藏查询条");
                }

            });
        },
        search: function () {
            $("#search").on("click", function () {
                tools.tableRefresh();
            });
        },
        tableRefresh: function () {
            $("#myTable").bootstrapTable('refreshOptions', {pageNumber:1});
            $("#myTable").bootstrapTable('refresh');
        },
        enterSearch: function () {
            $("body").on("keyup", function (e) {
                var code = e.charCode || e.keyCode;
                if (code == 13) {
                    //此处编写用户敲回车后的代码
                    tools.tableRefresh();
                }
            })
        },
        reset: function () {
            $("#reset").on("click", function () {
                bs.resetSearch($(".search"));
                if($("#laydate_box").length>0){
                    bs.resetTimeElems("#start","#end");
                }
                tools.tableRefresh();
            })
        },
        resetSelect: function ($obj) {
            $obj.val("");
            $obj.trigger("chosen:updated");
        },
        refresh: function () {
            $("#refresh").on("click", function () {
                $("#myTable").bootstrapTable('refresh');
            })
        },
        addModel: function () {
            $("#addModal").on("hide.bs.modal", function () {
                $("#keyAdd").val("");
                if(!$("#proAdd").prop("disabled")){
                    $("#proAdd").val("").trigger("chosen:updated");
                    $("#proModalAddInput").val("");
                }
            });
            $("#btnAdd").on("click", function () {
                $("#addModal").modal("show");
                $("#proModalAddInput").val($("#proAdd").val());
            })
        },
        saveModel: function () {
            $("#save").on("click", function () {
                $("#addModelForm").jqxValidator("validate");
            });
            $("#addModelForm").on("validationSuccess", function (event) {
                var obj = {};
                obj.province_code = $("#proAdd").val();
                obj.word_nameStr = $("#keyAdd").val();
                var nameArr=obj.word_nameStr.split(",");
                var isSame=bs.isRepeat(nameArr);
                if(isSame){
                    toastrCog.error("存在重复排除词！");
                    return;
                }
                $.ajax({
                    url: tools.url+"/excludeword/saveWords",
                    type: "post",
                    data: obj,
                    success: function (result) {
                        var msg = result.message;
                        var code = result.code;
                        var data = result.data;
                        if (code==1) {
                            tools.tableRefresh();
                            if(data && data.length>0){
                                var tip="该省份下排除词";
                                for(var i=0;i<data.length;i++){
                                    tip+=data[i]+",";
                                }
                                tip=tip.substr(0,tip.length-1);
                                tip+="已经存在!";
                                toastrCog.success(tip, 5000);
                            }else{
                                toastrCog.success("添加成功", 2000)
                            }
                        } else {
                            toastrCog.error(msg, 3000);
                        }
                        $("#addModal").modal("hide");
                    }
                });
            });
        },
        editModel: function () {
            $("#btnEdit").on("click", function () {
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                if (selectArr.length <= 0) {
                    toastrCog.error("请选择要编辑的数据！", 3000);
                } else if (selectArr.length > 1) {
                    toastrCog.error("请选择一条要编辑的数据！", 3000);
                } else if (selectArr[0].word_status == 1) {
                    toastrCog.error("排除词已启用，无法编辑。要编辑排除词,请先停用排除词。", 3000);
                } else {
                    $("#editModal").modal("show");
                    $("#proEdit").val(selectArr[0].province_code).trigger("chosen:updated");
                    $("#proModalEditInput").val(selectArr[0].province_code);
                    $("#keyEdit").val(selectArr[0].word_name);
                    $("#editModal").attr({"data-id":selectArr[0].id_excludeword,"data-code":selectArr[0].province_code,"data-name":selectArr[0].word_name});
                }
            });
            $("#saveEdit").on("click", function () {
                $("#editModelForm").jqxValidator("validate");
            });
            $("#editModelForm").on("validationSuccess", function (event) {
                var id = $("#editModal").attr("data-id");
                var name = $("#editModal").attr("data-name");
                if($("#keyEdit").val()!=name){
                    $.ajax({
                        type: "post",
                        url: tools.url+"/excludeword/updateById",
                        dataType: "json",
//                    contentType: "application/json",  //缺失会出现URL编码，无法转成json对象
                        data: {
                            id_excludeword: id,
                            word_name: $("#keyEdit").val()
                        },
                        success: function (data) {
                            if (data.code == 1) {
                                $("#myTable").bootstrapTable('refresh');
                                toastrCog.success(data.message, 1000)
                            } else {
                                toastrCog.error(data.message, 3000)
                            }
                        }
                    })
                }
                $("#editModal").modal("hide");

            });
        },
        delModel: function () {
            $("#btnDel").on("click", function () {
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                if (selectArr.length <= 0) {
                    toastrCog.error("请选择要删除的数据！", 3000);
                } else {
                    var delArr=[];
                    for (var i = 0; i < selectArr.length; i++) {
                        if (selectArr[i].word_status == 1) {
                            delArr.push(selectArr[i]);//用来存放已上线数据
                        }
                    }
                    if(delArr.length>0){
                        toastrCog.error("所选的数据包含已启用的排除词，请重新选择！", 3000);
                        return
                    }
                    $("#delModal").modal("show");
                    tools.delTipRender(selectArr);
                }
            });
            $("#delBtn").on("click", function () {
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                var ids = [];
                for (var i = 0; i < selectArr.length; i++) {
                    ids.push(selectArr[i].id_excludeword);
                }
                $.ajax({
                    type: "post",
                    url: tools.url+"/excludeword/removeWordsByIds",
//                    dataType: "json",
                    contentType: 'application/json;charset=UTF-8', //contentType很重要
                    data: JSON.stringify(ids),
                    success: function (data) {
                        if (data.code == 1) {
                            tools.tableRefresh();
                            toastrCog.success("删除成功", 1000)
                        } else {
                            toastrCog.error(data.message, 3000)
                        }
                        $("#delModal").modal("hide");
                    }
                });
            });
        },
        startModel: function () {
            $("#btnStart").on("click", function () {
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                var startArr = [];//用来存放已上线数据
                var stopArr = [];//用来存放未上线数据
                for (var i = 0; i < selectArr.length; i++) {
                    if (selectArr[i].word_status == 1) {
                        startArr.push(selectArr[i]);//保存已上线的数据
                    } else {
                        stopArr.push(selectArr[i]);//保存已上线的数据
                    }
                }
                if (selectArr.length <= 0) {//如果没有选择数据
                    toastrCog.error("请选择要上线的数据！", 3000);
                } else if (startArr.length > 0) {//如果选择了已上线的数据
                    toastrCog.error("所选模型包含已启用 " + tools.getStr(startArr, "word_name") + " 排除词，请重新选择！", 3000);
                } else {
                    tools.tipRender(1, selectArr, "启用");
                }
            });
            $("#startBtn").on("click", function () {
                $("#startBtn").html("请求中...请稍后").prop("disabled", true);
                var code = $("#startModal").attr("data-code");
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                var ids = [];
                for (var i = 0; i < selectArr.length; i++) {
                    ids.push(selectArr[i].id_excludeword);
                }
                $.ajax({
                    type: "post",
                    url:  tools.url+"/excludeword/updateStatusByIds",
                    dataType: "json",
//                    contentType: 'application/json;charset=UTF-8', //contentType很重要
                    data: {
                        idList: ids.join(","),
                        status:code
                    },
                    success: function (data) {
                        if (data.code == 1) {
                            $("#myTable").bootstrapTable('refresh');
                            toastrCog.success("操作成功", 1000)
                        } else {
                            toastrCog.error(data.message, 3000)
                        }
                        $("#startBtn").html("确定").prop("disabled", false);
                        $("#startModal").modal("hide");
                    }
                })
            });
        },
        stopModel: function () {
            $("#btnStop").on("click", function () {
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                var stopArr = [];//用来存放未上线数据
                for (var i = 0; i < selectArr.length; i++) {
                    if (selectArr[i].word_status == 0) {
                        stopArr.push(selectArr[i]);//保存未上线的数据
                    }
                }
                if (selectArr.length <= 0) {
                    toastrCog.error("请选择要停用的数据！", 3000);
                } else if (stopArr.length > 0) {
                    toastrCog.error("所选的数据包含已停用的排除词，请重新选择！", 2000);
                } else {
                    var ids = [];
                    for (var i = 0; i < selectArr.length; i++) {
                        ids.push(selectArr[i].id);
                    };
                    tools.tipRender(0, selectArr, "停用");
                }
            });
        },
        delTipRender: function (selectArr) {
            var modalElem = $("#delModal");
            modalElem.modal("show");
            $("#delName").html("您确定要删除所选的" +
                "<span style='color:rgb(50, 136, 226)'>" + selectArr.length + "</span>" +
                "个排除词" +
                "<span style='color:rgb(50, 136, 226)'>" + tools.getStr(selectArr, "word_name") + "</span>吗？");
            modalElem.attr("data-id", tools.getStr(selectArr, "id_excludeword"));
        },
        tipRender: function (type, selectArr, title) {
            var modalElem = $("#startModal");
            modalElem.modal("show");
            modalElem.find(".modal-title").html(title);
            $("#type").html(
                "确定要" + title + "所选的" +
                "<span style='color:rgb(50, 136, 226)'>" + selectArr.length + "</span>" +
                "个排除词" +
                "<span style='color:rgb(50, 136, 226)'>" + tools.getStr(selectArr, "word_name") + "</span>吗？");
            modalElem.attr("data-id", tools.getStr(selectArr, "id_excludeword"));
            modalElem.attr("data-code", type);
        },
        export: function () {
            $("#export").on("click", function () {
                if (tools.tableData.length == 0) {
                    toastrCog.error("没有可导出的数据哦！")
                    return;
                }
                var form = $("#exportForm");
                form.attr("action", tools.url+ "/resolve/downloadExcludeWord");
                form.find("input[name='province']").val($("#pro").val());
                form.find("input[name='word_name']").val($.trim($("#keyName").val()));
                form.find("input[name='word_status']").val($("#state").val());
                form.find("input[name='create_time_start']").val($("#start").val());
                form.find("input[name='create_time_end']").val($("#end").val());
                form[0].submit();
            })

        },
        updataSelect: function ($obj, val) {
            $obj.val(val);
            $obj.trigger("chosen:updated");
        },
        getStr: function (selectArr, code) {
            var str = "";
            for (var i = 0; i < selectArr.length; i++) {
                str += selectArr[i][code] + ",";
            }
            str = str.substr(0, str.length - 1);
            return str;
        }
    };
    var draggables = { //模态框拖动
        init: function () {
            this.draggable($('.modal').not("#addRuleModel"));
        },
        draggable: function (obj) {
            $(obj).draggable();
        }
    };
    var validateFun = {
        init: function () {
            this.initKeyValidatorAdd();
            this.initKeyValidatorEdit();
        },
        initKeyValidatorAdd: function () {
            $("#addModelForm").jqxValidator({
                rules: [
                    {
                        input: '#proModalAddInput',
                        message: '请选择省份!',
                        action: 'change,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() == "") {
                                result = false
                            }
                            return result;
                        }
                    },
                    {
                        input: '#keyAdd',
                        message: '排除词不能为空',
                        action: 'keyup,blur',
                        rule: 'required'
                    }
                    , {
                        input: '#keyAdd',
                        message: '排除词只能由汉字，英文，数字组合的50个字符以内，不能以逗号结束 且不能包含空格！',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            var reg=/^([\u4e00-\u9fa5]|[a-zA-Z0-9]){1,50}(,([\u4e00-\u9fa5]|[a-zA-Z0-9]){1,50})*$/;
                            if ($(input).val()!= "") {
                                if(!reg.test($(input).val())){
                                    return false
                                }
                            }
                            return result;
                        }
                    }
                ],
                hintType: "label"
            });
        },
        initKeyValidatorEdit: function () {
            $("#editModelForm").jqxValidator({
                rules: [
                    {
                        input: '#proModalEditInput',
                        message: '请选择省份!',
                        action: 'change,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() == "") {
                                result = false
                            }
                            return result;
                        }
                    },
                    {
                        input: '#keyEdit',
                        message: '排除词名称不能为空',
                        action: 'keyup,blur',
                        rule: 'required'
                    }
                    , {
                        input: '#keyEdit',
                        message: '排除词只能由汉字，英文，数字组合，且不能包含空格！',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            var reg=/^([\u4e00-\u9fa5]|[a-zA-Z0-9])+$/;
                            if ($(input).val()!= "") {
                                if(!reg.test($(input).val())){
                                    return false
                                }
                            }
                            return result;
                        }
                    }
                    , {
                        input: '#keyEdit',
                        message: '排除词名称不能多余'+tools.maxTextLength+'字！',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val()!= "") {
                                if($(input).val().length>50){
                                    return false
                                }
                            }
                            return result;
                        }
                    } , {
                        input: '#keyEdit',
                        message: "排除词名称已经存在!",
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var validate = true;
                            var url = tools.url+ "/excludeword/isExistInProvince";
                            if($(input).val()!=$("#editModal").attr("data-name")){
                                var data = {
                                    word_name: $(input).val(),
                                    province_code:$("#editModal").attr("data-code")
                                };
                                $.ajax({
                                    url: url,
                                    timeout: 10000,
                                    async: false,
                                    type: 'POST',
                                    data:data,
//                                contentType: "application/json",  //缺失会出现URL编码，无法转成json对象
                                    success: function (msg) {
                                        if (msg.data) {
                                            input.focus();
                                            validate = false;
                                        }
                                    }
                                });
                            }
                            return validate;
                        }
                    }
                ],
                hintType: "label"
            });
        }
    };
    // 批量导入
    var importfile = {
        init: function () {
            importfile.importModalInit();
            importfile.ifile();
            $("#btnAllAdd").on("click",function(){
                $("#importModal").modal("show");
            })
        },
        importModalInit: function () {
            $("#importModal").on("show.bs.modal", function () {
                $('#proModal').val("").trigger("chosen:updated");
                // 初始化文件上传控件
                $("#uploadDiv").html("").append("<div class='file-loading'><input id='uploadFile' name='file' type='file' /></div><div id='errorBlock' class='help-block'></div>");
                $("#uploadFile").fileinput({
                    language: 'zh',
                    uploadUrl: tools.url+"/resolve/upload",
                    allowedFileExtensions: ['xls', 'xlsx'],
                    elErrorContainer: '#errorBlock',
                    showPreview: false,
                    showUpload: false,
                    maxFileCount: 1,
                    enctype: 'multipart/form-data',
                    uploadExtraData: function (previewId, index) {
                        var data = {
                            province_code: $('#proModal').val()
                        };
                        return data;
                    }
                }).on("fileuploaded", function (event, data, previewId, index) {
                    var response=data.response;
                    var code = response.code;
                    if (code == "1") {
                        toastrCog.success(response.message);
                    } else {
                        toastrCog.error(response.message);
                    }
                    $("#importModal").modal("hide");
                    //刷新table和左侧树
                    $("#myTable").bootstrapTable("refresh");
                    $("#jstree").jstree("refresh");
                });
            });
        },
        ifile: function () {
            $("#importBtn").off("click").on("click", function () {
                var areaid = $('#proModal').val();
                var file = $("#uploadFile").val();
                if (areaid == "") {
                    toastrCog.error("请选择省份",2000);
                    return false;
                }
                if (file == "") {
                    toastrCog.error("请选择要上传的文件",2000);
                    return false;
                }
                // 校验通过上传
                $("#uploadFile").fileinput("upload");
            });
        }
    }
    $(function () {
        resize.init();
        tools.init();
        var oTable = new TableInit();
        oTable.Init();
        draggables.init();
        validateFun.init();
    })
</script>
</body>
</html>